package com.controller;

import com.pojo.ShopCommentImg;
import com.service.ShopCommentImgService;
import com.util.ServerResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

/**
 * Created by Administrator on 2020/3/20.
 */
@Api(tags = "用户店铺点评图片API")
@Controller
public class ShopCommentImgController {
    @Autowired
    private ShopCommentImgService shopCommentImgService;
    @ApiOperation(value ="添加点评图片",notes ="" )
    @PostMapping("/shopCommentImg")
    @ResponseBody
    public ServerResponse add(ShopCommentImg shopCommentImg){
        // ServerResponse serverResponse =
        //System.out.println("serverResponse:"+serverResponse);
        return shopCommentImgService.save(shopCommentImg);
    }

    @ApiOperation(value = "根据id删除图片",notes ="")
    @DeleteMapping("/shopCommentImg/{id}")
    @ResponseBody
    public ServerResponse del(@PathVariable("id")String id){
        ServerResponse serverResponse = shopCommentImgService.modifyStatus(Integer.valueOf(id));
        System.out.println("serverResponse:"+serverResponse);
        return serverResponse;
    }

    @ApiOperation(value ="修改用户信息",notes ="修改用户信息" )
    @PutMapping("/shopCommentImg")
    @ResponseBody
    public ServerResponse upd(ShopCommentImg shopCommentImg){
        System.out.println(shopCommentImg);
        ServerResponse serverResponse = shopCommentImgService.modify(shopCommentImg);
        return serverResponse;
    }
    /*
      根据id查询用户
   */
    @ApiOperation(value ="根据id查询点评图片")
    @GetMapping("/shopCommentImg/{id}")
    @ResponseBody
    public ServerResponse findById(@PathVariable("id") String id){
        System.out.println(id);
        ServerResponse serverResponse = shopCommentImgService.getById(Integer.valueOf(id));
        return serverResponse;
    }

    @ApiOperation(value ="查询点评图片信息")
    @GetMapping("/shopCommentImg")
    public String findAll(Model model){
        ServerResponse serverResponse = shopCommentImgService.getAll();
        model.addAttribute("info",serverResponse.getData());
        return "back/shop/shopCommentImg";
    }
}
